<?php

/*
===============================================================================
��������֧�����������

orderid	
���й���д����orderid

opstate	
�������״̬:
	0 ����֧���ɹ�
	-1 ���������Ч
	-2 ǩ�����
	-5 ����֧��ʧ��

ovalue	
ʵ��֧���Ľ���λԪ

ekaorderid
	����ӿ�v2.0 �汾����
	�˴ο���Ĺ���м�Ѷϵͳ�Ķ���Id��Ϊ���ֺ���ǰ�汾���ݣ���ֵ�����뷵�ؽ��ǩ����֤��

ekatime
	����ӿ�v2.0 �汾����
	�˴ο���Ĺ���м�Ѷϵͳ�Ķ�������ʱ�䡣��ʽΪ��/��/�� ʱ���֣��룬��2014/08/25 21:50:58��
	Ϊ���ֺ���ǰ�汾���ݣ���ֵ�����뷵�ؽ��ǩ����֤��
================================================================================
*/
header('Content-Type:text/html;charset=UTF-8');
require_once("../config/pay_config.php");
require_once("../eka/class.bankpay.php");
require_once('../../config.php');

//��ȡ���ص��������
$orderid        = trim($_GET['orderid']);
$opstate        = trim($_GET['opstate']);
$ovalue         = trim($_GET['ovalue']);
$ekaorderid		= trim($_GET['ekaorderid']);
$ekatime		= trim($_GET['ekatime']);

//���м�Ѷǩ����֤
$bankpay		= new bankpay();
$bankpay->key	= $eka_merchant_key;
$bankpay->recive();

//////////////////////////////////////////////////////////////////////////
// ���뵽��һ����˵��ǩ���Ѿ���֤�ɹ���
// ���������������Լ��Ĵ���, ���磺���Խ������������ݿ�


$bRet = true;
if($bRet){
$conn = mysql_connect($dbhost,$conf['db']['user'],$conf['db']['password']);
if (!$conn)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db($dbname,$conn);
mysql_query("SET NAMES UTF8");

$chaxun = mysql_query("SELECT state FROM ssc_order WHERE order_number = '".$r6_Order."'");
$jiancha = mysql_result($chaxun,0);
$chaxun2 = mysql_query("select actionIP from ssc_member_recharge where rechargeid= '".$r6_Order."'");
$actionIP = mysql_result($chaxun2,0);
$chaxun3 = mysql_query("select id from ssc_member_recharge where rechargeid= '".$r6_Order."'");
$id = mysql_result($chaxun3,0);
$chaxun4 = mysql_query("select uid from ssc_member_recharge where rechargeid= '".$r6_Order."'");
$uid = mysql_result($chaxun4,0);
$chaxun5 = mysql_query("select coin from ssc_members where uid= '".$uid."'");
$coin = mysql_result($chaxun5,0);
$chaxun6 = mysql_query("select value from ssc_params where name='czzs'");
$czzs = mysql_result($chaxun6,0);
if($czzs){
	$r3_Amt=$r3_Amt*(1+number_format($czzs/100,2,'.',''));
}
$inserts = "insert into ssc_coin_log (uid,type,playedId,coin,userCoin,fcoin,liqType,actionUID,actionTime,actionIP,info,extfield0,extfield1) values ('".$uid."',0,0,'".$r3_Amt."','".$coin."'+'".$r3_Amt."',0,1,0,UNIX_TIMESTAMP(),'".$actionIP."','����֧���Զ�����','".$id."','".$uid."')";
$update1 = "UPDATE ssc_order SET state = 2 WHERE order_number = '".$r6_Order."'";
$update2 = "UPDATE ssc_members SET coin = coin+'".$r3_Amt."' WHERE username = '".$r8_MP."'";
$update3 = "update ssc_member_recharge set state=2,rechargeTime=UNIX_TIMESTAMP(),rechargeAmount='".$r3_Amt."',coin='".$coin."', info='����֧���Զ�����' where rechargeid='".$r6_Order."'";

if($jiancha==0){
	   if($r1_Code==1){
                if(mysql_query($update1,$conn)){
                mysql_query($update2,$conn);
                mysql_query($update3,$conn);
                mysql_query($inserts,$conn);
				echo 'success';
                echo "���ѳɹ���ֵ�������µ�½ƽ̨����鿴,лл!";
				}else{
					echo "���Ͷ�ݳ���";
				}
	    }else{
	       echo "������Ϣ���۸�";
        }
}else{
    echo "���ѳ�ֵ�����𷴸�ˢ��,лл!";
	exit;
}
}
mysql_close($conn);


//////////////////////////////////////////////////////////////////////////
//���֮�󷵻سɹ�
/*
	Э��:
	0 �ɹ�
	-1 ���������Ч
	-2 ǩ�����
*/
die("opstate=0");
?>